module GrapeAPI
  module APICmsHelpers
    def format_user(users)
      data = {}
      users.each do |user|
        data_info = ""
        data_info = user.email.to_s + "^" + user.username.to_s + "^" + user.sign_in_count.to_s  + "^" + user.created_at.to_s
        data[user.id.to_s] = data_info
      end

      data
    end
    
    def format_apps(apps)
      data = {}
      apps.each do |app|
        data_info = ""
        data_info = app.b_user_id.to_s + "^" + app.app_id.to_s + "^" + app.app_name.to_s  + "^" + app.created_at.to_s
        data[app.app_id.to_s] = data_info
      end

      data
    end


    def unzip_file (file, destination)
      require 'rubygems'
      require 'zip'

      zip_flag = false

      Zip::File.open(file) { |zip_file|
        zip_file.each { |f|
          f_path=File.join(destination, f.name)
          FileUtils.mkdir_p(File.dirname(f_path))
          zip_file.extract(f, f_path) unless File.exist?(f_path)
          zip_flag = true
        }
      }

      zip_flag
    end
  # end download methed
  
  
  end
end